﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using KVB.Common;
using Customer_Profile.eCard.DBDao;

namespace Customer_Profile.eCard
{
    public partial class transferSearchList : System.Web.UI.Page
    {
        string strCardno = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["CARDNO"] != null)
            {
                strCardno = Request["CARDNO"].ToString();
                txtcardno.Value = strCardno;
                bindGrid();
            }
        }

        protected void GvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GvData.PageIndex = e.NewPageIndex;
            bindGrid();
        }

        private void bindGrid()
        {
            try
            {
                DataSet ds = TransferDao.getTransfers(strCardno);
                if (ds != null && ds.Tables.Count > 0)
                {
                    GvData.DataSource = ds.Tables[0];
                    GvData.DataBind();
                }
                else
                {
                    GvData.DataBind();
                }
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("bindGrid", ex.ToString());
            }
        }

        protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            /*
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //string Guid = GvData.DataKeys[e.Row.RowIndex].Value.ToString();
                //ImageButton ib = (ImageButton)e.Row.Cells[6].Controls[1];
                //ImageButton ibSend = (ImageButton)e.Row.Cells[7].Controls[1];
                //ib.Attributes.Add("onclick", "javascript:window.open('showResult.aspx?id=" + Guid + "');return false");
                //string SendStatus = e.Row.Cells[5].Text;
                //if (SendStatus.Equals("NO"))
                //{
                //    e.Row.Cells[5].Text = "<span style=color:red>" + SendStatus + "</span>";
                //}
                //if (e.Row.Cells[4].Text == "" || e.Row.Cells[4].Text.Equals("&nbsp;"))
                //{
                //    ibSend.Visible = false;
                //}
                //ibSend.Attributes.Add("Guid", Guid);
                //ibSend.Attributes.Add("ibid", e.Row.Cells[0].Text.ToString());
                ImageButton ib = (ImageButton)e.Row.Cells[8].Controls[1];
                ImageButton ibSend = (ImageButton)e.Row.Cells[9].Controls[1];
                ib.Attributes.Add("cardno", e.Row.Cells[0].Text.ToString());
                ibSend.Attributes.Add("cardno", e.Row.Cells[0].Text.ToString());
            }
            */
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Transfer.aspx?CARDNO=" + txtcardno.Value, true);
        }

        protected void imgbt_Click(object sender, ImageClickEventArgs e)
        {
            string cardno = ((ImageButton)sender).Attributes["cardno"].ToString();
            Response.Redirect("Transfer.aspx?CARDNO=" + cardno, true);
        }

        protected void imgbtsend_Click(object sender, ImageClickEventArgs e)
        {
            string cardno = ((ImageButton)sender).Attributes["cardno"].ToString();
            Response.Redirect("cflowSearchList.aspx?CARDNO=" + cardno, true);
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("mmdealSearch.aspx", true);
        }
    }
}